
<template>
  <div class="login">
    <div class="logo">
      <img src="@/assets/images/login.png" alt="" />
    </div>
    <van-form class="form" validate-first>
      <!-- 通过 pattern 进行正则校验 -->
      <van-field
        v-model="form.mobile"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ pattern, message: '请输入用户名' }]"
      />
      <van-field
        v-model="form.password"
        name="密码"
        type="password"
        label="密码"
        placeholder="密码"
        :rules="[{ pattern1, message: '请输入密码' }]"
      />
      <div class="one">
        <p>找回密码</p>
        <p @click="$router.push('/smslogin')">注册/验证码登录</p>
      </div>
      <div style="margin: 16px">
        <van-button class="btn" round block type="info" @click="loginBtn"
          >登录</van-button
        >
      </div>
    </van-form>
    <div class="otherLogin">
      <p style="font-size: 18px">第三方登录</p>
      <div class="footer" style="font-size: 18px">
        <div>
          <img src="../../assets/images/pay-wx.png" alt="" />
          <span>微信登录</span>
        </div>
        <div>
          <img src="../../assets/images/QQ.png" alt="" />
          <span>QQ登录</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getLogin } from "@/utils/api.js";
export default {
  name: "",
  components: {},
  data() {
    return {
      form: {
        mobile: "",
        password: "",
        type: 1,
        client: 1,
      },
      pattern: /^(?:(?:\+|00)86)?1[3-9]\d{9}$/,
      pattern1:
        /^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*? ])\S*$/,
    };
  },
  created() {},
  mounted() {},
  methods: {
    // 校验函数返回 true 表示校验通过，false 表示不通过
    validator(val) {
      return /1\d{10}/.test(val);
    },
    // 登录按钮
    loginBtn() {
      // console.log(this.pattern.test(this.username));
      getLogin(this.form).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.$router.push("/userIndex");
          localStorage.setItem("msmktoken", res.data.data.remember_token);
        }
      });
    },
  },
};
</script>
<style scoped lang='scss'>
.login {
  font-size: 20px;
  width: 100%;
  margin-top: 50px;
  .logo {
    text-align: center;
    margin-bottom: 50px;
    img {
      width: 525px;
      height: 115px;
    }
  }
  .form {
    width: 83%;
    margin: 0 auto;
    .one {
      font-size: 17px;
      color: #999999;
      display: flex;
      justify-content: space-between;
    }
    div {
      .btn {
        background-color: rgb(253, 102, 20);
        border-color: rgb(253, 102, 20);
        margin-top: 50px;
      }
    }
  }
  .otherLogin {
    p {
      width: 100%;
      text-align: center;
    }
    .footer {
      display: flex;
      width: 600px;
      justify-content: space-between;
      align-items: center;
      margin: auto;
      margin-top: 30px;
      div {
        flex: 1;
        text-align: center;
        img {
          vertical-align: middle;
          width: 54px;
          height: 42px;
          margin-right: 10px;
        }
      }
    }
  }
}
</style>
